package org.elcom.sources;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class Config {
	
	public static String ip = "";	//IP server
	public static int port = 0;		//PORT server
	public static String user = "";	//user name
	public static String pass = "";	//password
	public static String formatClientDir = "";	//format of directory 
	
	public static int waitingTime = 3000; //time use to reconnect if disconnect	
	public static String remoteDirPath = ""; //source dir
	public static String saveDirPath = ""; // destination dir
	public static String downloadedFileDir = "";	//location of file downloaded.txt
	public static String templateDir = "";
	
	public Config() throws IOException {

		Properties pro = new Properties();
		try {
			pro.load(new FileInputStream("C:/config.txt"));
		} catch (FileNotFoundException e) {
			System.out.println("Cannot find the file config.txt");
		} catch (IOException e) {
			System.out.println("Error to read file config.txt");
		} catch (Exception e) {
			System.out.println("Error");
		}
		
		ip = pro.getProperty("IP").toString().trim();
		port = Integer.parseInt(pro.getProperty("PORT").toString().trim());
		user = pro.getProperty("USER").toString().trim();
		pass = pro.getProperty("PASSWORD").toString();
		remoteDirPath = pro.getProperty("SERVERDIR").toString().trim();
		saveDirPath = pro.getProperty("CLIENTDIR").toString().trim();
		formatClientDir = pro.getProperty("FORMATCLIENTDIR").toString().trim();
		downloadedFileDir = pro.getProperty("DOWNLOADEDFILEDIR").toString().trim();
		templateDir = pro.getProperty("TEMPLATEDIR").toString().trim();
			
		createTemplateFolder(templateDir);
	}
	//create folder Template
	public static void createTemplateFolder(String dirName) throws IOException{
		File file = new File(dirName);
		if (!file.exists()) {
			file.mkdirs();
		}
	}
	
}
